package cn.smbms.converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.core.convert.converter.Converter;

public class StringToDateConverter implements Converter<String, Date> {

	private String pattern = "yyyy-MM-dd hh:mm:ss";

	public StringToDateConverter(String pattern) {
		this.pattern = pattern;
	}

	public Date convert(String str) {

		SimpleDateFormat sdf = new SimpleDateFormat(pattern);

		try {
			Date date = sdf.parse(str);
			return date;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return null;
	}

}
